package com.example.village.mqtt;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
public class TopicConsumerListener {

    public static String is_success = "0";

    public static String door_success = "0";

    //topic模式的消费者
    @JmsListener(destination="${spring.activemq.topic-name2}", containerFactory="topicListener")
    public void readActiveQueue(String message) {
        is_success = "0";
        message = asciiToString(message);
        System.out.println("topic接受到：" + message);
        if (message.equalsIgnoreCase("0") || message.equalsIgnoreCase("1") || message.equalsIgnoreCase("2")) {
            is_success = message;
        }
    }

    //topic模式的消费者
    @JmsListener(destination="${spring.activemq.topic-dBack}", containerFactory="topicListener")
    public void readDoorActiveQueue(String message) {
        door_success = "0";
        message = asciiToString(message);
        System.out.println("topic接受到：" + message);
        if (message.equalsIgnoreCase("0") || message.equalsIgnoreCase("1") || message.equalsIgnoreCase("2") || message.equalsIgnoreCase("3") || message.equalsIgnoreCase("4") || message.equalsIgnoreCase("5")) {
            door_success = message;
        }
    }

    public String asciiToString(String value)
    {
        StringBuffer sbu = new StringBuffer();
        String[] chars = value.split(",");
        for (int i = 0; i < chars.length; i++) {
            sbu.append((char) Integer.parseInt(chars[i]));
        }
        return sbu.toString();
    }
}
